package com.fengye.common;


//import lombok.extern.slf4j.Slf4j;

import java.io.File;

//@Slf4j
public class Application {
    public void traverseFolder2(String path) {

        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (null == files || files.length == 0) {
                System.out.println("文件夹是空的!");
                return;
            } else {
                for (File file2 : files) {
                    if (file2.isDirectory()) {
                        file2 = rename(file2);
                        traverseFolder2(file2.getAbsolutePath());
                    } else {
                        rename(file2);
//                        System.out.println("文件:" + file2.getAbsolutePath());
                    }
                }
            }
        } else {
            System.out.println("文件不存在!");
        }
    }

//    public void traverseFolder(String path) {
//
//        File file = new File(path);
//        if (file.exists()) {
//            File[] files = file.listFiles();
//            if (null == files || files.length == 0) {
//                System.out.println("文件夹是空的!");
//                return;
//            }
//            for (File exist_file : files) {
//                traverseFolder(rename(exist_file).getAbsolutePath());
//            }
//        } else {
//            System.out.println("文件不存在!");
//        }
//    }

    public File rename(File original) {
        String dirname = original.getAbsolutePath();
        String replace_string= " 【www.zxit8.com】";
        if (dirname.contains(replace_string)) {
            String new_filename = original.getAbsolutePath().replace(replace_string, "");
            File new_file = new File(new_filename);
            original.renameTo(new_file);
//            logger.info();
            System.out.println(String.format("重命名:%s-->%s", original.getName(), new_filename));
            return new_file;
        }
        return original;
    }

    public static void main(String[] args) {
        Application application = new Application();
//        String path = "R:\\黑马\\heima\\23 微服务社交平台【十次方】·\\十次方资料(1)\\十次方资料";
        String path = "H:\\JAVA分布式优惠券系统后台";
        application.traverseFolder2(path);
    }
}
